<?php defined('SYSPATH') or die('No direct script access.');

class Model_Article extends ORM {

  protected $_table_name = 'articles';
  protected $_sorting = array('id' => 'desc');

  protected $_has_many = array(
      'articles_category' => array('through' => 'articles_articles_categories'),
      'articles_tag' => array('through' => 'articles_articles_tags'),
      'article_comments' => array('model' => 'comments_article', 'foreign_key' => 'article_id'),
  );
  
  public function validate_add_article($array) {

    $validation = Validate::factory($array)
                    ->rule('title', 'not_empty')
                    ->rule('seo_title', 'not_empty')
                    ->rule('text', 'not_empty')
                    ->rule('article_tags', 'is_array')
                    ->rule('categories', 'not_empty');

    return $validation;
  }

}
